package com.game.view.component
{
	import base.BaseObject;
	import com.game.engine.MainGame;
	import com.game.engine.phys.Vector2D;
	
	import flash.events.Event;
	import flash.geom.Point;
	import flash.text.TextField;
	
	public class StopPoint extends BaseObject
	{
		
		public function StopPoint()
		{
			super();
			velocity = Vector2D.zero;
			gravity = 0;
		}
		
		private var _data:Point;
		public var idx:int;
		public var isBoss:Boolean;
		public var betweenRandL:int = 100;
		public var isStart:Boolean = false;
		public var isSendMonster:Boolean = false;
		
		override protected function beforeAdded():void
		{
			_data = new Point();
			if (MainGame.getIns().levelData.levelName == "玲珑宝塔")
			{
				betweenRandL = 300;
			}
		}
		
		override protected function onAdded():void
		{
			CONFIG::DEBUG{
				graphics.beginFill(0x00FFCC);
				graphics.drawRect(-30, -40, 60, 80);
				graphics.endFill();
				var txt:TextField = new TextField();
				txt.defaultTextFormat.align = "center";
				txt.text += "stop";
				txt.x = -txt.textWidth / 2;
				txt.y = -txt.textHeight / 2;
				addChild(txt);
			}
		}
		
		public function setXY(param1:Number, param2:Number):void
		{
			_data.x = param1;
			_data.y = param2;
		}
		
		public function touch():void
		{
			if (!isSendMonster)
			{
				isSendMonster = true;
				isStart = true;
				for each(var appearPoint:MonsterAppearPoint in gc.pWorld.getMonsterAppearArray())
				{
					if (appearPoint.stopPointIdx == idx)
					{
						appearPoint.start();
					}
				}
			}
		}
		
		override public function render(ratio:Number = 1):void
		{
		
		}
		
		override public function renderAnimate():void
		{
			if(!isStart)
			{
				return;
			}
			var allOver:Boolean = true;
			for each(var appearPoint:MonsterAppearPoint in gc.pWorld.getMonsterAppearArray())
			{
				if (appearPoint.stopPointIdx == idx && !appearPoint.isOver)
				{
					allOver = false;
				}
			}
			if (allOver && gc.pWorld.getMonsterArray().length == 0)
			{
				destroy();
			}
		}
		
		public function getLeftDataX():Number
		{
			return betweenRandL;
		}
		
		public function getDataX():Number
		{
			return _data.x;
		}
		
		override protected function beforeRemoved():void
		{
			var idx:int = gc.pWorld.getStopPointArray().indexOf(this);
			if(idx >= 0 && idx != gc.pWorld.getStopPointArray().length - 1)
			{
				if (gc.vController != null)
				{
					gc.vController.setAutoCamera();
				}
				if (gc.gameInfo != null && idx < 4)
				{
					gc.gameInfo.addForwardPanel();
				}
			}
		}
		
		override public function destroy():void
		{
			isStart = false;
			removeFromParent();
			isReadyToDestroy = true;
		}
	}
}
